<?
include('../scaffold/content.php');
include('../controller/handler.php');
include('../controller/philomousia.php');

include('var.inc.php');

$hd = new Handler();
$searched = $_POST['content'];

//echo "<ul><li>a</li></ul>";

if($searched!=NULL) {
	$hd = new Handler();
	$ph = new Philomousia();
	setlocale(LC_ALL, $hd->getSetLocale());
	$quantity = $hd->getAutocompleterResults();
	$offset = 0;
	$hd->openDB();
	$contents = $ph->searchContent($searched, $hd, $offset, $quantity);
	$hd->closeDB();

	if(count($contents)==0) {?>
		<ul><li id="error">Nessun risultato</li></ul>
	<?} else {?>
	<ul>
		<?foreach($contents as $content) {?>
			<li id="<?echo $content->getId();?>" class="<?echo $content->getType();?>">
			<?
			$text = $content->getTitle();
			if(strlen($text)>25) {
				$text = substr($text, 0, $hd->getSearchNumChars())."...";
			}
			?>
			<p class="title_searched"><?echo $text;?></p>
			<p class="details_searched">di <?echo $content->getAuthor();?> in 
				<?echo $section[$content->getType()];?></p>
			<p class="date_searched"><?echo strftime($hd->getDateFormat(), strtotime($content->getDate()));?></p>
			</li>
		<?}?>
	</ul>
	<?
	}
}
?>